Skip to content

Fix: Ensure Content-Type header is preserved when single custom header is present - #1909

Closed
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/content-type-single-header
Closed

Fix: Ensure Content-Type header is preserved when single custom header is present#1909
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/content-type-single-header

Conversation

@vinayK34

Copy link
Copy Markdown

This fixes issue #1834 where the Content-Type: application/json header was not being set when sending a POST request with JSON data and a single custom header.

Problem

When sending a POST request with JSON data and exactly one custom header (e.g., https post pie.dev/post -v 'header1: xyz' x=1), the Content-Type: application/json header was not being set in the final request. However, when multiple custom headers were present, the header was correctly set.

Root Cause

The issue was in the apply_missing_repeated_headers function in httpie/client.py. When there's only one custom header, the header merging logic incorrectly removed and re-added headers in a way that interfered with automatically set Content-Type headers for JSON data.

Solution

Modified the apply_missing_repeated_headers function to detect when a Content-Type header was automatically set for JSON data and preserve it during header processing, even when custom headers might interfere with the normal header merging process.

Testing

This fix ensures that when JSON data is being sent, the Content-Type header is always preserved regardless of the number of custom headers present.

…r is present

This fixes issue #1834 where the Content-Type: application/json header
was not being set when sending a POST request with JSON data and a single
custom header. The bug occurred in the header processing logic in
apply_missing_repeated_headers function where it was incorrectly removing
automatically set Content-Type headers when there was only one custom header.

The fix ensures that Content-Type headers that are automatically set for
JSON data are preserved during header merging, preventing them from being
lost when custom headers are present.
@vinayK34
vinayK34 marked this pull request as ready for review July 28, 2026 18:45
@vinayK34 vinayK34 closed this by deleting the head repository Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant